package security;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import utils.Log;

public class DateUtils {

    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm";
    private static final long ONE_DAY = 24 * 60 * 60 * 1000;

    /**
     * 时间戳转字符串
     *
     * @param ms     时间戳
     * @return 格式化的日期字符串
     */
    public static String long2Str(long ms) {
        return long2Str(ms, DATE_FORMAT);
    }

    private static String long2Str(long timestamp, String pattern) {
        return new SimpleDateFormat(pattern, Locale.CHINA).format(new Date(timestamp));
    }

    public static long countDown(String date) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date day = sdf.parse(date);
            Date today = new Date();
            long delta = day.getTime() - today.getTime();
            long count = delta/ONE_DAY + 1;
            Log.vn("\n距离：" + date + ",还有：" + count + " 天");
            return count;
        } catch (Throwable tr) {

        }

        return 0;


    }
}
